import request from '../../utils/service'
import apiBase from '../api-base'
// import axios from "axios";

const apiVer = apiBase.version.v1

const evidenceservice = {}

// 从工行系统获取项目信息
evidenceservice.queryEvidence = function (params) {
    return request({
      // url: apiVer + '/evidence/queryEvidence',
      url: '/fileTmpl/queryTOesSysDoc',
      method: 'POST',
      data: params
    })
  //   axios.post('http://localhost:7111/fileTmpl/queryTOesSysDoc',params).then((response)=>{
  //     return response
  // }).catch((response)=>{
  //     console.log(response)
  // })
  }
evidenceservice.queryEvidenceDoc = function (params) {
    return service({
        // url: apiVer + '/evidence/queryEvidence',
        url: '/tOesRpt/queryTOesRptFile',
        method: 'post',
        data: params
    })
}

evidenceservice.getNowFormatDate = function() {
    var date = new Date();
    var seperator1 = "-";
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = year + seperator1 + month + seperator1 + strDate;
    return currentdate;
};

evidenceservice.formatDate = function(date, fmt){
    if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
    }
    let o = {
        'M+': date.getMonth() + 1,
        'd+': date.getDate(),
        'h+': date.getHours(),
        'm+': date.getMinutes(),
        's+': date.getSeconds()
    };
    for (let k in o) {
        if (new RegExp(`(${k})`).test(fmt)) {
            let str = o[k] + '';
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? str : padLeftZero(str));
        }
    }
    return fmt;
};

evidenceservice.baseUrl = 'http://128.16.176.9:7111';

function padLeftZero (str) {
    return ('00' + str).substr(str.length);
};

export default evidenceservice